import VueRouter from "vue-router";
import Index from "@/views/index.vue";

const router = new VueRouter({
  routes: [
    //首页
    {
      path: "/",
      name: "Index",
      component: Index,
    },

    //产品页
    {
      path: "/product/:id",
      name: "product",
      //路由懒加载，当我展示对应的路由的时候才加载对应的文件，可以解决首页白屏
      //webpack魔法注释，将来打包的时候会把product组件单独打包成一个js，去到对应的路由才会加载，减轻服务器压力
      component: () =>
        import(/* webpackChunkName:"product"*/ "../views/product.vue"),
    },

    //详细页
    {
      //路由路径跳转时params传参id，所以这里接收路径后面要写:id,传啥就写啥
      path: "/detail/:id",
      name: "detail",
      component: () =>
        import(/*webpackChunkName:"detail"*/ "../views/detail.vue"),
    },

    //购物车页
    {
      path: "/cart",
      name: "cart",
      component: () => import(/*webpackChunkName:"Cart"*/ "../views/Cart.vue"),
    },

    //登录注册
    {
      path: "/login",
      name: "login",
      component: () =>
        import(/*webpackChunkName:"login"*/ "../views/Login.vue"),
    },

    //订单页面
    {
      path: "/order",
      name: "order",
      redirect:'/order/orderconfirm',
      component: () =>
        import(/*webpackChunkName:"order"*/ "../views/order.vue"),

      children: [
        //订单确认
        {
          path: "orderconfirm",
          name: "orderconfirm",
          component: () =>
            import(
              /*webpackChunkName:"orderconfirm"*/ "../views/OrderConfirm.vue"
            ),
        },

        // //订单列表
        {
          path: "orderlist",
          name: "orderlist",
          component: () =>
            import(/*webpackChunkName:"orderlist"*/ "../views/OrderList"),
        },

        //订单支付
        {
          path: "orderpay",
          name: "orderpay",
          component: () =>
            import(/*webpackChunkName:"orderpay"*/ "../views/OrderPay.vue"),
        },
      ],
    },

      // 个人中心主页
      {
        path: "/gerenzhuye",
        name: "gerenzhuye",
        component: () =>
          import(/*webpackChunkName:"gerenzhuye"*/ "../views/gerenzhuye"),
      },

      
  ],
});

export default router;
